<?php
class AgentRelatedBehavior extends CActiveRecordBehavior{
	public $isOpen = true;
	public $field;
	Public $role;
	
//	Public function afterConstruct($event){
//		list($module) = explode('/', Yii::app()->request->pathInfo);
//		if($this->isOpen && $module == 'admin'){
//			$this->agentR();
//		}else{
//			return '';
//		}
//	}
	
	Public function agentR(){
		if(Yii::app()->adminUser->isGuest){
			return '';		
		}else{
			if(Yii::app()->adminUser->role == $this->role){
				$criteria = $this->owner->getDbCriteria();
				$criteria->with = array('aRelateds');
				$criteria->compare('aRelateds.'.$this->field,Yii::app()->adminUser->id);
				$criteria->compare('aRelateds.status','ST_PASSED');
			}
			return $this->owner;
		}
	}
}

?>